package com.lingdian.busapp.activity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
import com.lingdian.busapp.BusListViewActivity;
import com.lingdian.busapp.R;
import com.lingdian.busapp.common.BaseActivity;
import com.lingdian.busapp.common.CommonService;


public class QueryBusActivity extends BaseActivity implements OnClickListener {
	
	CommonService commonService = new CommonService(this);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_query_bus);
        findViewById(R.id.action_query_bus_btn).setOnClickListener(this);
    }



	@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.query_bus, menu);
        return true;
    }


	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.action_query_bus_btn:
			queryBus();
			break;

		default:
			break;
		}
	}


	private void queryBus() {
		String url ="/bus/busInfo?code=101110904&startAt=2015-09-13&agent=mobile";
		commonService.setTag("queryBus").get(url);
	}



	@Override
	public void processFailure(HttpException arg0, String arg1) {
		
	}



	@Override
	public void processSuccess(ResponseInfo<String> response) {
		if(this.getTag().equals("queryBus")){
			String result = response.result;
			Intent intent = new Intent(QueryBusActivity.this,BusListViewActivity.class);
			intent.putExtra("result", result);
			startActivity(intent);
		}
			
	}
    
}
